<template>
  <div class="user-container">
    <!-- 背景装饰元素 -->
    <div class="decoration-circle decoration-circle-1"></div>
    <div class="decoration-circle decoration-circle-2"></div>
    <div class="decoration-circle decoration-circle-3"></div>
    <transition name="fade" appear>
      <el-card class="search-card" shadow="hover">
        <el-form :inline="true" class="form">
          <el-form-item label="用户名:">
            <el-input
              placeholder="请输入搜索用户名"
              v-model="keyword"
              clearable
              prefix-icon="Search"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              size="default"
              :disabled="!keyword"
              @click="search"
              icon="Search"
            >
              搜索
            </el-button>
            <el-button
              type="info"
              size="default"
              @click="reset"
              icon="RefreshRight"
            >
              重置
            </el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </transition>
    <transition name="slide-fade" appear>
      <el-card class="table-card" shadow="hover">
        <div class="button-group">
          <el-button type="primary" size="default" @click="addUser" icon="Plus">
            添加用户
          </el-button>
          <el-button
            type="danger"
            size="default"
            :disabled="!selectIdArr.length"
            @click="deleteSelectUser"
            icon="Delete"
          >
            批量删除
          </el-button>
        </div>
        <!-- table展示用户信息 -->
        <el-table
          @selection-change="selectChange"
          style="margin: 8px 0"
          border
          stripe
          highlight-current-row
          :data="userArr"
          class="user-table"
        >
          <el-table-column type="selection" align="center"></el-table-column>
          <el-table-column
            label="索引"
            align="center"
            type="index"
          ></el-table-column>
          <el-table-column
            label="ID"
            align="center"
            prop="id"
            width="50"
            sortable
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            label="用户名"
            align="center"
            prop="login"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            label="密码"
            align="center"
            prop="password"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            label="用户名称"
            align="center"
            prop="name"
            width="90"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            label="性别"
            align="center"
            width="60"
            prop="sex"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            label="年龄"
            align="center"
            width="60"
            prop="age"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column label="权限" align="center">
            <template #default="{ row }">
              <span v-if="row.role == 1">
                <el-tag type="success">会员</el-tag>
              </span>
              <span v-else><el-tag color="skyblue">非会员</el-tag></span>
            </template>
          </el-table-column>
          <el-table-column
            label="地址"
            align="center"
            width="80"
            prop="address"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            label="创建时间"
            align="center"
            width="200"
            show-overflow-tooltip
          >
            <template #default="{ row }">
              {{ formatTime(row.createTime) }}
            </template>
          </el-table-column>
          <el-table-column
            label="电话号码"
            align="center"
            prop="phone"
            width="90"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column label="操作" width="270px" align="center">
            <template #="{ row, $index }">
              <el-button
                type="primary"
                size="small"
                icon="User"
                @click="setRole(row)"
                class="action-btn"
              >
                分配角色
              </el-button>
              <el-button
                type="primary"
                size="small"
                icon="Edit"
                @click="updateUser(row)"
                class="action-btn edit-btn"
              >
                编辑
              </el-button>
              <el-popconfirm
                :title="`你确定要删除${row.name}?`"
                width="260px"
                @confirm="deleteUser(row.id)"
              >
                <template #reference>
                  <el-button
                    type="danger"
                    size="small"
                    icon="Delete"
                    class="action-btn delete-btn"
                  >
                    删除
                  </el-button>
                </template>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页器 -->
        <el-pagination
          v-model:current-page="pageNo"
          v-model:page-size="pageSize"
          :page-sizes="[10, 20, 30, 40]"
          :background="true"
          layout="prev, pager, next, jumper,->,sizes,total"
          :total="total"
          @current-change="getHasUser"
          @size-change="handler"
          class="pagination"
        />
        <div class="page-info">
          当前显示 {{ (pageNo - 1) * pageSize + 1 }} -
          {{ Math.min(pageNo * pageSize, total) }} 条，共 {{ total }} 条记录
        </div>
      </el-card>
    </transition>
    <!-- 抽屉结构:完成添加新的用户账号|更新已有的账号信息 -->
    <el-drawer
      v-model="drawer"
      size="400px"
      destroy-on-close
      :before-close="cancel"
      custom-class="custom-drawer"
    >
      <!-- 头部标题:将来文字内容应该动态的 -->
      <template #header>
        <h4 class="drawer-title">
          <el-icon class="drawer-icon" :size="20">
            <component :is="userParams.id ? 'Edit' : 'Plus'"></component>
          </el-icon>
          {{ userParams.id ? '更新用户' : '添加用户' }}
        </h4>
      </template>
      <!-- 身体部分 -->
      <template #default>
        <el-form
          :model="userParams"
          :rules="rules"
          ref="formRef"
          label-width="80px"
          class="user-form"
        >
          <el-form-item label="用户名" prop="login">
            <el-input
              placeholder="请输入用户名"
              v-model="userParams.login"
              prefix-icon="User"
              class="custom-input"
            ></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input
              placeholder="请输入密码"
              v-model="userParams.password"
              prefix-icon="Lock"
              show-password
              class="custom-input"
            ></el-input>
          </el-form-item>
          <el-form-item label="用户名称" prop="name">
            <el-input
              placeholder="请输入用户名称"
              v-model="userParams.name"
              prefix-icon="UserFilled"
              class="custom-input"
            ></el-input>
          </el-form-item>
          <el-form-item label="性别" prop="sex">
            <el-select
              v-model="userParams.sex"
              placeholder="请选择用户性别"
              style="width: 100%"
              class="custom-input"
            >
              <el-option label="男" value="男"></el-option>
              <el-option label="女" value="女"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="用户年龄" prop="age">
            <el-input-number
              placeholder="请输入用户年龄"
              max="100"
              min="1"
              v-model="userParams.age"
              style="width: 100%"
              class="custom-input"
              controls-position="right"
            ></el-input-number>
          </el-form-item>
          <el-form-item label="用户地址" prop="address">
            <el-select
              v-model="userParams.address"
              placeholder="请选择用户地址"
              style="width: 100%"
              filterable
              class="custom-input"
            >
              <el-option
                v-for="item in provinceArr"
                :key="item.name"
                :label="item.value"
                :value="item.name"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="用户电话" prop="phone">
            <el-input
              placeholder="请输入用户电话"
              v-model="userParams.phone"
              prefix-icon="Phone"
              class="custom-input"
            ></el-input>
          </el-form-item>
        </el-form>
      </template>
      <template #footer>
        <div class="drawer-footer">
          <el-button @click="cancel" icon="Close">取消</el-button>
          <el-button type="primary" @click="save" icon="Check">确定</el-button>
        </div>
      </template>
    </el-drawer>
    <!-- 抽屉结构:用户某一个已有的账号进行职位分配 -->
    <el-drawer
      v-model="drawer1"
      size="400px"
      destroy-on-close
      :before-close="() => (drawer1 = false)"
      custom-class="custom-drawer"
    >
      <template #header>
        <h4 class="drawer-title">
          <el-icon class="drawer-icon" :size="20"><UserFilled /></el-icon>
          分配角色(职位)
        </h4>
      </template>
      <template #default>
        <el-form label-width="80px" class="user-form">
          <el-form-item label="用户姓名">
            <el-input
              v-model="userParams.login"
              :disabled="true"
              prefix-icon="User"
              class="custom-input"
            ></el-input>
          </el-form-item>
          <el-form-item label="职位列表">
            <div class="role-selection">
              <el-checkbox
                @change="handleCheckAllChange"
                v-model="checkAll"
                :indeterminate="isIndeterminate"
                class="select-all"
              >
                <el-icon><Check /></el-icon>
                全选
              </el-checkbox>
              <!-- 显示职位的的复选框 -->
              <el-checkbox-group
                v-model="userRole"
                @change="handleCheckedCitiesChange"
                class="role-checkbox-group"
              >
                <el-checkbox
                  v-for="(role, index) in allRole"
                  :key="index"
                  :label="role"
                  class="role-checkbox"
                >
                  <span class="role-name">{{ role.name }}</span>
                </el-checkbox>
              </el-checkbox-group>
            </div>
          </el-form-item>
        </el-form>
      </template>
      <template #footer>
        <div class="drawer-footer">
          <el-button @click="drawer1 = false" icon="Close">取消</el-button>
          <el-button type="primary" @click="confirmClick" icon="Check">
            确定
          </el-button>
        </div>
      </template>
    </el-drawer>
  </div>
</template>
<script setup lang="ts">
import useLayOutSettingStore from '@/store/modules/setting'
import { ref, onMounted, reactive, nextTick } from 'vue'

import qs from 'qs'
import {
  reqSelectUser,
  reqRemoveUser,
  reqUserInfo,
  reqAddOrUpdateUser,
  reqAllRole,
  reqSetUserRole,
} from '@/api/acl/user'
import type { Records, User } from '@/api/acl/user/type'
import { ElMessage } from 'element-plus'
import { UserResponseData } from '@/api/acl/user/type'
import { formatTime } from '@/util/time.ts'
//默认页码
let pageNo = ref<number>(1)
//一页展示几条数据
let pageSize = ref<number>(13)
//用户总个数
let total = ref<number>(0)
//存储全部用户的数组
let userArr = ref<Records>([])
//定义响应式数据控制抽屉的显示与隐藏
let drawer = ref<boolean>(false)
//控制分配角色抽屉显示与隐藏
let drawer1 = ref<boolean>(false)
//存储全部职位的数据
let allRole = ref<AllRole>([])
//当前用户已有的职位
let userRole = ref<AllRole>([])
//收集用户信息的响应式数据
let userParams = reactive<User>({
  address: '',
  age: 0,
  createTime: [],
  id: 0,
  isExist: 0,
  login: '',
  phone: '',
  role: 0,
  sex: '',
  name: '',
  password: '',
})
//准备一个数组存储批量删除的用户的ID
let selectIdArr = ref<User[]>([])
//存储用户地址的数组  中国所有省和直辖市
let provinceArr = ref<any>([
  {
    name: '北京市',
    value: '北京市',
  },
  {
    name: '天津市',
    value: '天津市',
  },
  {
    name: '上海市',
    value: '上海市',
  },
  {
    name: '重庆市',
    value: '重庆市',
  },
  {
    name: '河北省',
    value: '河北省',
  },
  {
    name: '河南省',
    value: '河南省',
  },
  {
    name: '云南省',
    value: '云南省',
  },
  {
    name: '辽宁省',
    value: '辽宁省',
  },
  {
    name: '黑龙江省',
    value: '黑龙江省',
  },
  {
    name: '湖南省',
    value: '湖南省',
  },
  {
    name: '安徽省',
    value: '安徽省',
  },
  {
    name: '山东省',
    value: '山东省',
  },
  {
    name: '新疆维吾尔自治区',
    value: '新疆维吾尔自治区',
  },
  {
    name: '江苏省',
    value: '江苏省',
  },
  {
    name: '浙江省',
    value: '浙江省',
  },
  {
    name: '江西省',
    value: '江西省',
  },
  {
    name: '湖北省',
    value: '湖北省',
  },
  {
    name: '广西壮族自治区',
    value: '广西壮族自治区',
  },
  {
    name: '甘肃省',
    value: '甘肃省',
  },
  {
    name: '山西省',
    value: '山西省',
  },
  {
    name: '内蒙古自治区',
    value: '内蒙古自治区',
  },
  {
    name: '陕西省',
    value: '陕西省',
  },
  {
    name: '吉林省',
    value: '吉林省',
  },
  {
    name: '福建省',
    value: '福建省',
  },
  {
    name: '贵州省',
    value: '贵州省',
  },
  {
    name: '广东省',
    value: '广东省',
  },
  {
    name: '青海省',
    value: '青海省',
  },
  {
    name: '西藏自治区',
    value: '西藏自治区',
  },
  {
    name: '四川省',
    value: '四川省',
  },
  {
    name: '宁夏自治区',
    value: '宁夏自治区',
  },
  {
    name: '海南',
    value: '海南',
  },
  {
    name: '台湾',
    value: '台湾',
  },
  {
    name: '香港',
    value: '香港',
  },
  {
    name: '澳门',
    value: '澳门',
  },
  {
    name: '海外',
    value: '海外',
  },
])

//获取form组件实例
let formRef = ref<any>()
//定义响应式数据:收集用户输入进来的关键字
let keyword = ref<string>('')
//获取模板setting仓库
let settingStore = useLayOutSettingStore()
//组件挂载完毕
onMounted(() => {
  getHasUser()
})
//获取全部已有的用户信息
const getHasUser = async (pager = 1) => {
  //收集当前页码
  let data = qs.stringify({
    name: keyword.value,
    page: pageNo.value,
    pageSize: pageSize.value,
  })
  pageNo.value = pager
  let result: UserResponseData = await reqUserInfo(data)
  if (result.code == 1) {
    total.value = result.data.total
    userArr.value = result.data.records
  }
}
//分页器下拉菜单的自定义事件的回调
const handler = () => {
  getHasUser()
}
//添加用户按钮的回调
const addUser = () => {
  //抽屉显示出来
  drawer.value = true
  //清空数据
  Object.assign(userParams, {
    id: 0,
    username: '',
    name: '',
    password: '',
    phone: '',
    sex: '',
    address: '',
    age: 0,
  })
  //清除上一次的错误的提示信息
  nextTick(() => {
    formRef.value.clearValidate('login')
    formRef.value.clearValidate('name')
    formRef.value.clearValidate('password')
    formRef.value.clearValidate('phone')
    formRef.value.clearValidate('address')
    formRef.value.clearValidate('age')
    formRef.value.clearValidate('sex')
  })
}
//更新已有的用户按钮的回调
//row:即为已有用户的账号信息
const updateUser = (row: User) => {
  //抽屉显示出来
  drawer.value = true
  //存储收集已有的账号信息
  Object.assign(userParams, row)
  //清除上一次的错误的提示信息
  nextTick(() => {
    formRef.value.clearValidate('username')
    formRef.value.clearValidate('name')
  })
}
//保存按钮的回调
const save = async () => {
  //点击保存按钮的时候,务必需要保证表单全部复合条件在去发请求
  await formRef.value.validate()
  //保存按钮:添加新的用户|更新已有的用户账号信息
  let result: any = await reqAddOrUpdateUser(userParams)
  //添加或者更新成功
  if (result.code == 1) {
    //关闭抽屉
    drawer.value = false
    //提示消息
    ElMessage({
      type: 'success',
      message: userParams.id ? '更新成功' : '添加成功',
    })
    //获取最新的全部账号的信息
    // getHasUser(userParams.id ? pageNo.value : 1);
    //浏览器自动刷新一次
    window.location.reload()
  } else {
    //关闭抽屉
    drawer.value = false
    //提示消息
    ElMessage({
      type: 'error',
      message: userParams.id ? '更新失败' : '添加失败',
    })
  }
}
//取消按钮的回调
const cancel = () => {
  //关闭抽屉
  drawer.value = false
}
//校验用户名字回调函数
const validatorUsername = (rule: any, value: any, callBack: any) => {
  //用户名字|昵称,长度至少五位
  if (value.trim().length >= 5) {
    callBack()
  } else {
    callBack(new Error('用户名字至少五位'))
  }
}
//校验用户名字回调函数
const validatorname = (rule: any, value: any, callBack: any) => {
  //用户名字|昵称,长度至少五位
  if (value.trim().length >= 5) {
    callBack()
  } else {
    callBack(new Error('用户昵称至少五位'))
  }
}
const validatorPassword = (rule: any, value: any, callBack: any) => {
  //用户名字|昵称,长度至少五位
  if (value.trim().length >= 6) {
    callBack()
  } else {
    callBack(new Error('用户密码至少六位'))
  }
}
const validatorPhone = (rule: any, value: any, callBack: any) => {
  //用户手机号码至少十一位
  if (value.trim().length >= 11) {
    callBack()
  } else {
    callBack(new Error('用户手机号码至少十一位'))
  }
}
//表单校验的规则对象
const rules = {
  //用户名字
  login: [{ required: true, trigger: 'blur', validator: validatorUsername }],
  //用户昵称
  name: [{ required: true, trigger: 'blur' }],
  //用户的密码
  password: [{ required: true, trigger: 'blur', validator: validatorPassword }],
  //用户的地址
  address: [{ required: true, trigger: 'blur' }],
  //用户的年龄
  age: [{ required: true, trigger: 'blur' }],
  //用户的性别
  sex: [{ required: true, trigger: 'blur' }],
  //用户的手机号
  phone: [{ required: true, trigger: 'blur', validator: validatorPhone }],
}
//分配角色按钮的回调
const setRole = async (row: User) => {
  //存储已有的用户信息
  Object.assign(userParams, row)
  //获取全部的职位的数据与当前用户已有的职位的数据
  let result: any = await reqAllRole(userParams.id as number)
  if (result.code == 1) {
    //存储全部的职位
    allRole.value = result.data.allRoles
    //存储当前用户已有的职位
    userRole.value = result.data.checkedRoles
    //抽屉显示出来
    drawer1.value = true
  }
}

//收集顶部复选框全选数据
const checkAll = ref<boolean>(false)
//控制顶部全选复选框不确定的样式
const isIndeterminate = ref<boolean>(true)
//顶部的全部复选框的change事件
const handleCheckAllChange = (val: boolean) => {
  //val:true(全选)|false(没有全选)
  userRole.value = val ? allRole.value : []
  //不确定的样式(确定样式)
  isIndeterminate.value = false
}
//顶部全部的复选框的change事件
const handleCheckedCitiesChange = (value: string[]) => {
  //顶部复选框的勾选数据
  //代表:勾选上的项目个数与全部的职位个数相等，顶部的复选框勾选上
  checkAll.value = value.length === allRole.value.length
  //不确定的样式
  isIndeterminate.value = value.length !== allRole.value.length
}
//确定按钮的回调(分配职位)
const confirmClick = async () => {
  //收集参数
  let data: SetRoleData = {
    userId: userParams.id as number,
    roleIdList: userRole.value.map((item) => {
      return item.id as number
    }),
  }
  //分配用户的职位
  let result: any = await reqSetUserRole(data)
  if (result.code == 200) {
    //提示信息
    ElMessage({ type: 'success', message: '分配职务成功' })
    //关闭抽屉
    drawer1.value = false
    //获取更新完毕用户的信息,更新完毕留在当前页
    getHasUser(pageNo.value)
  }
}

//删除某一个用户
const deleteUser = async (userId: number) => {
  let result: any = await reqRemoveUser(userId)
  if (result.code == 1) {
    ElMessage({ type: 'success', message: '删除成功' })
    await getHasUser(userArr.value.length > 1 ? pageNo.value : pageNo.value - 1)
  }
}
//table复选框勾选的时候会触发的事件
const selectChange = (value: any) => {
  selectIdArr.value = value
}
//批量删除按钮的回调
const deleteSelectUser = async () => {
  //整理批量删除的参数
  let idsList: any = selectIdArr.value.map((item) => {
    return item.id
  })
  //批量删除的请求
  let result: any = await reqSelectUser(idsList)
  if (result.code == 200) {
    ElMessage({ type: 'success', message: '删除成功' })
    getHasUser(userArr.value.length > 1 ? pageNo.value : pageNo.value - 1)
  }
}

//搜索按钮的回调
const search = () => {
  //根据关键字获取相应的用户数据
  getHasUser()
  //清空关键字
  keyword.value = ''
}
//重置按钮
const reset = () => {
  settingStore.refresh = !settingStore.refresh
}
</script>

<style scoped>
/* 添加过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

.slide-fade-enter-active {
  transition: all 0.5s ease-out;
}

.slide-fade-enter-from {
  transform: translateY(20px);
  opacity: 0;
}

.user-container {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: calc(100vh - 60px);
}

.search-card {
  margin-bottom: 20px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
  transition: all 0.3s ease;
}

.search-card:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1) !important;
  transform: translateY(-2px);
}

.table-card {
  margin-bottom: 20px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
  transition: all 0.3s ease;
}

.table-card:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1) !important;
}

.button-group {
  margin-bottom: 15px;
  display: flex;
  justify-content: space-between;
}

.button-group .el-button {
  transition: all 0.3s ease;
  border-radius: 6px;
}

.button-group .el-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.user-table {
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 15px !important;
  transition: all 0.3s ease;
}

.user-table .el-table__row {
  transition: all 0.2s ease;
}

.user-table .el-table__row:hover {
  background-color: #f0f9ff !important;
}

.pagination {
  margin-top: 20px;
  display: flex;
  justify-content: center;
}

.drawer-title {
  font-size: 20px;
  color: #303133;
  margin: 0;
  font-weight: 600;
  position: relative;
  padding-left: 12px;
}

.drawer-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 18px;
  background: linear-gradient(45deg, #409eff, #67c23a);
  border-radius: 2px;
}

.user-form {
  padding: 10px 20px;
}

.user-form .el-form-item {
  margin-bottom: 22px;
}

.user-form .el-input,
.user-form .el-select,
.user-form .el-input-number {
  transition: all 0.3s ease;
}

.user-form .el-input:hover,
.user-form .el-select:hover,
.user-form .el-input-number:hover {
  transform: translateY(-2px);
}

.drawer-footer {
  display: flex;
  justify-content: flex-end;
  gap: 15px;
  width: 100%;
  padding: 10px 20px;
  border-top: 1px solid #ebeef5;
}

.drawer-footer .el-button {
  transition: all 0.3s ease;
  border-radius: 6px;
  padding: 10px 20px;
}

.drawer-footer .el-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.role-selection {
  display: flex;
  flex-direction: column;
  gap: 15px;
  background-color: #f9fafc;
  padding: 15px;
  border-radius: 8px;
}

.select-all {
  margin-bottom: 8px;
  font-weight: bold;
  color: #409eff;
}

.role-checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
}

.role-checkbox {
  margin-right: 15px;
  transition: all 0.2s ease;
}

.role-checkbox:hover {
  transform: translateY(-2px);
}

.el-tag {
  border-radius: 4px;
  padding: 2px 8px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.el-tag:hover {
  transform: scale(1.05);
}

.el-table .el-button {
  transition: all 0.3s ease;
}

.el-table .el-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.el-form-item__content {
  transition: all 0.3s ease;
}

/* 自定义抽屉样式 */
.custom-drawer {
  border-radius: 16px 0 0 16px;
  overflow: hidden;
}

/* 按钮样式增强 */
.search-btn,
.add-btn {
  background: linear-gradient(45deg, #409eff, #67c23a);
  border: none;
  font-weight: 500;
}

.reset-btn {
  background: linear-gradient(45deg, #909399, #c0c4cc);
  border: none;
  color: white;
  font-weight: 500;
}

.delete-btn {
  background: linear-gradient(45deg, #f56c6c, #e6a23c);
  border: none;
  font-weight: 500;
}

/* 表格样式增强 */
.user-container {
  position: relative;
  min-height: 100vh;
  padding: 20px;
  overflow: hidden;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e8f0 100%);
}

/* 装饰元素 */
.decoration-circle {
  position: absolute;
  border-radius: 50%;
  opacity: 0.6;
  z-index: 0;
  animation: float 8s ease-in-out infinite;
  filter: blur(60px);
}

.decoration-circle-1 {
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, #6366f1, transparent);
  top: -100px;
  right: -100px;
  animation-delay: 0s;
}

.decoration-circle-2 {
  width: 250px;
  height: 250px;
  background: radial-gradient(circle, #10b981, transparent);
  bottom: 10%;
  left: -100px;
  animation-delay: 2s;
}

.decoration-circle-3 {
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, #f59e0b, transparent);
  bottom: 30%;
  right: 10%;
  animation-delay: 4s;
}

/* 卡片样式 */
.search-card,
.table-card {
  position: relative;
  z-index: 1;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(10px);
  background-color: rgba(255, 255, 255, 0.9);
  border: none;
  overflow: hidden;
  margin-bottom: 20px;
}

.search-card {
  padding: 10px;
}

.table-card {
  padding: 15px;
}

/* 按钮样式 */
.button-group {
  display: flex;
  gap: 12px;
  margin-bottom: 15px;
}

.el-button {
  border-radius: 8px;
  transition: all 0.3s ease;
  font-weight: 500;
}

.el-button--primary {
  background: linear-gradient(to right, #6366f1, #4f46e5);
  border: none;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.el-button--primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.3);
}

.el-button--danger {
  background: linear-gradient(to right, #ef4444, #dc2626);
  border: none;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}

.el-button--danger:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(239, 68, 68, 0.3);
}

.el-button--info {
  background: linear-gradient(to right, #64748b, #475569);
  border: none;
  color: white;
  box-shadow: 0 4px 12px rgba(100, 116, 139, 0.2);
}

.el-button--info:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(100, 116, 139, 0.3);
}

/* 表格操作按钮样式 */
.action-btn {
  margin: 0 4px;
  transition: all 0.3s;
}

.action-btn:hover {
  transform: translateY(-2px);
}

.edit-btn {
  background: linear-gradient(to right, #3b82f6, #2563eb);
  border: none;
}

.delete-btn {
  background: linear-gradient(to right, #ef4444, #dc2626);
  border: none;
}

/* 表格样式 */
.user-table {
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}

.el-table {
  --el-table-header-bg-color: #f8fafc;
  --el-table-row-hover-bg-color: #f1f5f9;
  border-radius: 10px;
}

.el-table th.el-table__cell {
  font-size: 14px;
  font-weight: 600;
  background-color: #f8fafc;
  color: #334155;
  transition: background-color 0.3s;
  padding: 12px 0;
}

.el-table th.el-table__cell:hover {
  background-color: #f1f5f9 !important;
}

.el-table__row {
  transition: all 0.3s;
}

.el-table__row:hover td {
  background-color: #f1f5f9 !important;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* 标签样式 */
.el-tag {
  border-radius: 6px;
  padding: 2px 8px;
  font-weight: 500;
}

/* 分页器美化 */
.pagination {
  margin: 20px 0 10px;
  padding: 10px;
  background-color: rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  display: flex;
  justify-content: center;
}

.page-info {
  text-align: center;
  color: #64748b;
  font-size: 13px;
  margin-bottom: 15px;
}

/* 抽屉样式 */
.custom-drawer {
  border-radius: 16px 0 0 16px;
  overflow: hidden;
}

.drawer-title {
  font-size: 18px;
  color: #334155;
  margin: 0;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.drawer-icon {
  background: linear-gradient(to right, #6366f1, #4f46e5);
  color: white;
  padding: 6px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.drawer-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.user-form {
  padding: 10px;
}

/* 表单输入框样式 */
.custom-input {
  .el-input__wrapper {
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
    transition: all 0.3s;

    &:hover {
      box-shadow: 0 2px 8px rgba(99, 102, 241, 0.15);
    }

    &.is-focus {
      box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
    }
  }
}

.el-input__inner:focus,
.el-textarea__inner:focus {
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.el-select .el-input__wrapper {
  border-radius: 8px;
}

.el-input-number {
  width: 100%;
  border-radius: 8px;

  .el-input__wrapper {
    border-radius: 8px;
  }
}

/* 角色选择区域 */
.role-selection {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px;
  background-color: #f8fafc;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
  transition: all 0.3s;
}

.role-selection:hover {
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.08);
  transform: translateY(-2px);
}

.select-all {
  margin-bottom: 15px;
  font-weight: 600;
  color: #334155;
  padding: 6px 10px;
  background-color: rgba(99, 102, 241, 0.08);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.role-checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 5px;
}

.role-checkbox {
  margin-right: 0;
  margin-bottom: 5px;
  transition: all 0.3s;
  padding: 6px 8px;
  border-radius: 6px;
}

.role-checkbox:hover {
  background-color: rgba(99, 102, 241, 0.05);
}

.role-name {
  margin-left: 4px;
  font-weight: 500;
  color: #475569;
}

/* 动画效果 */
@keyframes float {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-20px) scale(1.05);
  }
}

.fade-enter-active,
.fade-leave-active {
  transition:
    opacity 0.6s ease,
    transform 0.6s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
  transform: translateY(-20px);
}

.slide-fade-enter-active {
  transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);
}

.slide-fade-leave-active {
  transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);
}

.slide-fade-enter-from,
.slide-fade-leave-to {
  transform: translateY(30px);
  opacity: 0;
}

/* 添加响应式调整 */
@media screen and (max-width: 768px) {
  .user-container {
    padding: 10px;
  }

  .button-group {
    flex-direction: column;
    gap: 10px;
  }

  .pagination {
    flex-wrap: wrap;
  }
}
</style>
